var ROL001 = {};


ROL001.loadDataTable = function(isSearch) {
    
        $('#dataTable')
	    .dataTable(
		    {
			bDestroy : true,
			bProcessing : false,
			bServerSide : true, 
			bLengthChange : false,
			bFilter : false,
			sAjaxSource : "getAllRole",
			fnServerParams : function(aoData) {
			    aoData.push({
				"name" : "role.roleName",
				"value" : $('#roleName').val()
			    }, {
				"name" : "role.roleDesc",
				"value" : $('#roleDesc').val()
			    }, {
				"name" : "role.active",
				"value" : $('#active').val()
			    });
			},
			columns : [ {
			    "data" : "roleId",
			    "sClass" : "center"
			}, {
			    "data" : "roleName"
			}, {
			    "data" : "roleDesc"
			}, {
			    "data" : "userGrant",
			    "sClass" : "center"
			}, {
			    "data" : "roomGrant",
			    "sClass" : "center"
			}, {
			    "data" : "residentGrant",
			    "sClass" : "center"
			}, {
			    "data" : "active",
			    "sClass" : "center"
			} ],
			aaSorting: [[1, 'asc']],
			columnDefs : [
				{
				    render : function(data, type, row) {
					 return  _COMMON.StatusRender[data];
				    },
				    targets : 6
				},
				{
				    render : function(data, type, row) {
					return data==null || data==''? '-' : _COMMON.GrantColumnRender[data];
				    },
				    targets : 3
				},
				{
				    render : function(data, type, row) {
					return   data==null || data==''? '-' :_COMMON.GrantColumnRender[data];
				    },
				    targets : 4
				},
				{
				    render : function(data, type, row) {
					return   data==null || data==''? '-' :_COMMON.GrantColumnRender[data];
				    },
				    targets : 5
				},
    	                   {
    	                      render: function ( data, type, row ) {
    	                	   return  _COMMON.ButtonRender.editBtn('ROL001.onEdit('+data+')' , _COMMON.isUserHide) + '&nbsp;'+
    	                	   	_COMMON.ButtonRender.delBtn('ROL001.onDelete('+data+')', _COMMON.isUserHide);
    	                       },
    	                       targets: 0
    	                   },
    	                   { 'bSortable': false, 'aTargets': [ 0 ] }
    	               ],
        });
    
};

ROL001.clearHeaderCriteria = function(){
    $('.required').unValidate();
    $('#roleName').clear();
    $('#roleDesc').clear();
//    $('#lastName').clear();
//    $('#role').clear();
//    $('#email').clear();
    $('#active').clear();
};


ROL001.onDelete = function(id) {

    $("#confirm").html("Do you want to delete ?");

    $("#confirm").dialog({
        resizable: false,
        modal: true,
        title: "Confirm Delete",
        height: 180,
        width: 300,
        buttons: {
            "Yes": function () {
                $(this).dialog('close');
                
                location = 'delete?role.roleId='+id;
                
            },
                "No": function () {
                $(this).dialog('close');
            }
        }
    });
};

ROL001.onEdit = function(name) {
    location = 'ROL001A?role.roleId='+name;
};

ROL001.init = function() {
//	$("#btnSave").show();
//	$("#btnUpdate").hide();
};


$(document).ready(function() {    
    
    _COMBOBOX.StatusCombo('active');
    
    ROL001.loadDataTable();

    $("#btnSearch").click(function() {
    	$('.required').unValidate();
    	ROL001.loadDataTable(true);
    });
    
    $("#btnClear").click(function() {
	ROL001.clearHeaderCriteria();
    });
    
});
